//
//  MineHeaderView.m
//  DS_PJ_01
//
//  Created by 宋畅 on 2016/12/17.
//  Copyright © 2016年 zhiqiyun. All rights reserved.
//

#import "MineHeaderView.h"
#import "UIImageView+AFNetworking.h"

#define headerHeight (sScreenWith/2-20)

#define imageWidth WidthAuto(110)


@interface MineHeaderView ()

@property(nonatomic,strong)UIImageView *headImgeView;

@end

@implementation MineHeaderView

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        self.frame = CGRectMake(0, 0, sScreenWith, headerHeight);
        [self _initVars];
    }
    return self;
}


-(void)_initVars
{
    UIImageView *headImgeView=[[UIImageView alloc]init];
    headImgeView.frame= CGRectMake(sScreenWith/2 - imageWidth/2, headerHeight/2 - imageWidth/2, imageWidth, imageWidth);
    [headImgeView setBackgroundColor:RGB(200, 200, 200, 1)];
    [headImgeView setCornerRadius:5];
    headImgeView.clipsToBounds=YES;
    headImgeView.userInteractionEnabled=YES;
    UITapGestureRecognizer* headImageViewClick = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageButtonClick:)];
    headImageViewClick.numberOfTapsRequired = 1; // 单击
    [headImgeView addGestureRecognizer:headImageViewClick];
    [self addSubview:headImgeView];
    self.headImgeView = headImgeView;
}

-(void)drawRect:(CGRect)rect
{
    [self.headImgeView setImageWithURL:[NSURL URLWithString:self.headeImageUrl] placeholderImage:[UIImage imageNamed:@"zanwutuxiang"]];
}

-(void)imageButtonClick:(UIGestureRecognizer *)ges
{
    if (self.headImageClick) {
        self.headImageClick();
    }
}

-(void)refreshHeadVew:(id)head
{
    if ([head isKindOfClass:[UIImage class]]) {
        [self.headImgeView setImage:head];
    }
    else if ([head isKindOfClass:[NSString class]]){
        [self.headImgeView setImageWithURL:[NSURL URLWithString:head] placeholderImage:[UIImage imageNamed:@"zanwutuxiang"]];
    }
    else if ([head isKindOfClass:[NSURL class]]){
        [self.headImgeView setImageWithURL:head placeholderImage:[UIImage imageNamed:@"zanwutuxiang"]];
    }
}
@end
